package model

import (
	jsoniter "github.com/json-iterator/go"
	"time"
)

type Wpr struct {
	ID        uint      `gorm:"primary_key"`
	CreatedAt time.Time `json:"createdTime"`
	UpdatedAt time.Time `json:"updatedTime"`

	MakerID   uint `json:"makerID"` //制作人ID
	MakerUser User `gorm:"ForeignKey:makerID"`

	CheckerID uint `json:"checkUserID"` //审核人ID
	CheckUser User `gorm:"ForeignKey:CheckerID"`

	CheckTime time.Time `json:"checkTime"` //审核日期
	Comments  string    `json:"comments"`  //审核意见

	CreateDate time.Time `json:"createDate"`
}

type CustomWpr struct {
	ID   uint `json:"id"`
	Type int  `json:"type"`

	Maker struct {
		ID       uint   `json:"id"`
		UserName string `json:"userName"`
	} `json:"maker"`

	Checker struct {
		ID       uint   `json:"id"`
		UserName string `json:"userName"`
	} `json:"checker"`

	CheckTime time.Time `json:"checkTime"`

	CreateDate time.Time `json:"createDate"`
	Comments   string    `json:"comments"`
}

type WprCopy struct {
	Wpr
}

func (u *WprCopy) MarshalJSON() ([]byte, error) {
	a := CustomWpr{
		ID:         u.ID,
		CreateDate: u.CreateDate,
		CheckTime:  u.CheckTime,
		Comments:   u.Comments,
	}

	a.Maker.ID = u.MakerUser.ID
	a.Maker.UserName = u.MakerUser.UserName

	a.Checker.ID = u.CheckUser.ID
	a.Checker.UserName = u.CheckUser.UserName
	return jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(a)
}